/*
 * v4_ch01_avg_price.cpp
 *
 *  Created on: 2012-8-28
 *      Author: JamesZOU
 */

#include <iostream>
#include "v4_ch01_sales_item.h"

int avg_price(){
    // declare variables to hold running sum and data for the next record
    v4_ch01_sales_item total, trans;

    // is there data to process?
    if (std::cin >> total) {
        // if so, read the transaction records
        while (std::cin >> trans)
            if (total.same_isbn(trans))
                // match: update the running total
                total = total + trans;
            else {
                // no match: print & assign to total
                std::cout << total << std::endl;
                total = trans;
            }
        // remember to print last record
        std::cout << total << std::endl;
    } else {
        // no input!, warn the user
        std::cout << "No data?!" << std::endl;
        return -1;  // indicate failure
    }

    return 0;
}

//int main(){
//	return avg_price();
//}



